//
//  AppFile.m
//  GKBHouse
//
//  Created by  on 12-8-11.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "AppFile.h"
#import "LoginController1.h"
@implementation AppFile
+ (BOOL)is_file_exsit:(NSString *)fileName
{
    NSFileManager *fileManage = [NSFileManager defaultManager];
    BOOL exsit = [fileManage fileExistsAtPath:fileName];
    return exsit;
}

+ (NSString *)documentsPath:(NSString *)fileName {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    return [documentsDirectory stringByAppendingPathComponent:fileName];
}
+ (void)saveSuccessLoginUser:(NSString *)name
{
    if (!name) {
        return;
    }
    NSString *LoginUserFile = [AppFile documentsPath:@"successLoginUser.dat"];
    NSMutableArray *userArray = [NSMutableArray arrayWithContentsOfFile:LoginUserFile];
    if (userArray) {
        if (![userArray containsObject:name]) {
            [userArray addObject:name];
        }
    }
    else
    {
        userArray = [NSMutableArray array];
        [userArray addObject:name];
    }
    [userArray writeToFile:LoginUserFile atomically:YES];
}
+ (NSArray *)successLoginUserArray
{
    NSString *LoginUserFile = [AppFile documentsPath:@"successLoginUser.dat"];
    NSMutableArray *userArray = [NSMutableArray arrayWithContentsOfFile:LoginUserFile];
    return userArray;
}
+ (NSString *)sceneFile
{
   // return nil;
    NSString *usrName = [LoginController1 currentUser];
    if (usrName) {
        usrName = [usrName stringByAppendingString:@".scene"];
        NSString *sceneFile = [AppFile documentsPath:usrName];
        return sceneFile;
        
    }
    return nil;
}

//NSArray *array = [AppFile sceneFileArray];
//NSLog(@"%@", array);
+ (NSArray *)sceneFileArray
{
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSArray *path =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *file = [path objectAtIndex:0]; //获得Document系统文件目录路径
    NSDirectoryEnumerator *direnum = [fileManager enumeratorAtPath:file ]; //遍历目录
    // NSMutableArray *files = [NSMutableArray arrayWithCapacity:50];
    NSMutableArray *files = [NSMutableArray array];
    NSString *fileName;
    while((fileName = [direnum nextObject])){
        if([[fileName pathExtension] isEqualToString:@"scene"]){ //遍历条件
            NSCharacterSet *charSet = [NSCharacterSet characterSetWithCharactersInString:@".scene"];
            fileName = [fileName stringByTrimmingCharactersInSet:charSet];
            [files addObject:fileName];
            NSLog(@"%@",fileName);
        }
    }
    return files;
}
@end
